package com.zz.ad.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

/**
 * Auther: zhangzhen
 * Date: 2019/8/19 22:35
 * Description:
 */
@Slf4j
@Component
public class PreRequestFilter extends ZuulFilter {
    @Override
    public String filterType() { // 过滤器类型
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int filterOrder() { // 执行顺序，数字越小，顺序越高，越先被执行
        return 0;
    }

    @Override
    public boolean shouldFilter() { // 是否需要执行这个过滤器，true执行，false不执行
        return true;
    }

    @Override
    public Object run() throws ZuulException { // 具体操作

        RequestContext ctx = RequestContext.getCurrentContext();
        ctx.set("startTime", System.currentTimeMillis());

        return null;
    }
}
